package com;

import java.util.Date;
import java.util.stream.Stream;

public class ThreadOne {
    public static void main(String[] args) {
//        Thread thread = new Thread(()->{
//            while (true) {
//                System.out.println(new Date());
//                try {
//                    Thread.sleep(3000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        thread.run();
        Runnable runnable = ()->{


                System.out.println(new Date());
            System.out.println(Thread.currentThread().getName());

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        };

        while (true) {
            if(Thread.currentThread().getName().equals("main")){
                Thread.yield();
                System.exit(0);
            }
            else {
                runnable.run();
            }
        }

    }
}
